{% extends './layout.tpl' %}
{% block css_assets %}
{% endblock %}

{% block content %}


    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>重置密码</h2>
            <p>{{ msg }}</p>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon iconfont icon-youxiang" for="user-login-username"></label>
                    <input type="text" id="mobile" name="mobile"  lay-verify="mobile" placeholder="手机号" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon iconfont icon-unlock" for="user-login-username"></label>
                    <input type="password" name="password"  lay-verify="password" placeholder="新密码" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon iconfont icon-queren" for="user-login-username"></label>
                    <input type="text" name="reset_code"  lay-verify="password2" placeholder="重置码" class="layui-input">
                </div>

                <div class="layui-form-item mt30">
                    <button class="layui-btn layui-btn-fluid" lay-submit=""  lay-filter="user-login-submit">提交</button>
                </div>
            </form>
        </div>
    </div>

{% endblock %}



{% block js_assets %}


    <script>

        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form
                ,layer = layui.layer

            form.verify({
                password : function (value) {

                    if(!passwordReg.test(value)){
                        return value.trim().length == 0 ? '请设置新密码' : passwordErrorMsg;
                    }
                },
                mobile : function(value){
                    var reg=/^1[3|4|5|7|8][0-9]{9}$/;
                    if(!reg.test(value)){
                        return '手机号码格式有误';
                    }
                },
            });

            //监听提交
            form.on('submit(user-login-submit)', function(data){

                submit(data.field)
                return false;
            });


        });

        function submit(data){
            var params = {
                password:data.password,
                reset_code:data.reset_code,
                mobile : data.mobile
            }

            $.post("/sale/login/password/retrieve/reset",params,function(result){
                if(result.status !=200){
                    layer.msg(result.msg,{icon:2})
                    return false
                }

                layer.msg("密码重置成功，请重新登录",{icon:1},function(){
                    window.location.href = "/sale/login"
                })
            });
        }
    </script>
{% endblock %}


